# -*- coding: utf-8 -*-
import sys
import threading
import tkinter
from io import BytesIO
from tkinter import *
from tkinter import filedialog

import xlrd
import xlwt
import xlutils
import numpy as np
from xlutils import copy
import openpyxl
from openpyxl import load_workbook

class MyGui:
    def __init__(self, init_window_name):
        self.write_to_temp_button = None
        self.get_type_button = None
        self.init_window_name = init_window_name

    # 设置窗口
    def set_init_window(self):
        global message_count
        message_count = 0
        self.init_window_name.title("BssYnndJtls脚本工具   v2.0")
        self.init_window_name.geometry('1050x550+300+100')
        self.init_window_name.attributes("-alpha", 0.9)
        self.init_window_name.resizable(False, False)

        self.write_to_temp_button = Button(self.init_window_name, text="卡片表转模板", width=25,
                                               command=lambda: threading.Thread(target=self.excel_table_by_name, args=(1,)).start())
        self.write_to_temp_button.grid(row=6, column=0, padx=5, pady=5)

        self.write_to_temp_button = Button(self.init_window_name, text="卡片表转模板(A0101\\A0203)", width=25,
                                               command=lambda: threading.Thread(target=self.excel_table_by_name, args=(2,)).start())
        self.write_to_temp_button.grid(row=6, column=1, padx=5, pady=5)

        self.get_type_button = Button(self.init_window_name, text="提取资产编号", width=25,
                                                   command=lambda: threading.Thread(target=self.get_type).start())
        self.get_type_button.grid(row=6, column=2, padx=5, pady=5)

        # 处理结果展示
        self.result_data_Text = Text(self.init_window_name, width=148, height=35)
        self.result_data_Text["bg"] = "#e6d2d5"
        self.result_data_Text.grid(row=0, column=0, rowspan=5, columnspan=3, padx=5, pady=5)
        sly = Scrollbar(self.init_window_name)
        sly['command'] = self.result_data_Text.yview
        # sly.grid(row=0, column=3, rowspan=5, sticky=S + W + E + N) 好像可以不显示
        slx = Scrollbar(self.init_window_name, orient=HORIZONTAL)
        slx['command'] = self.result_data_Text.xview
        # slx.grid(row=5, column=2, sticky=S + W + E + N) 好像可以不显示
        self.result_data_Text.insert(END,
                                     """Design by
    __________             _____.___.                 .___   ____. __  .__          
    \______   \______ _____\__  |   | ____   ____   __| _/  |    _/  |_|  |   ______
     |    |  _/  ___//  ___//   |   |/    \ /    \ / __ |   |    \   __|  |  /  ___/
     |    |   \___ \ \___ \ \____   |   |  |   |  / /_/ /\__|    ||  | |  |__\___ \ 
     |______  /____ /____  >/ ______|___|  |___|  \____ \________||__| |____/____  >
            \/    \/     \/ \/           \/     \/     \/                        \/ 
""")
        self.result_data_Text.insert(END, """
        \n\n
——————————————————————————————————————————————————————————————————————————""")
        self.result_data_Text.update()

    def excel_table_by_name(self, type):
        if(type == 1):
            self.result_data_Text.insert(END,"————————————————————————————————————————————————————————————————\n")
            datastyle = xlwt.XFStyle()
            datastyle.num_format_str = 'yyyy-mm-dd'
            datastyle_year = xlwt.XFStyle()
            datastyle_year.num_format_str = 'yyyy'
            self.result_data_Text.insert(END,"开始读取Excel......\n")
            self.result_data_Text.insert(END,"————————————————————————————————————————————————————————————————\n")

            try:
                org_table = xlrd.open_workbook('E:\\A.常用文件夹\\驻点\\Python tool\\录入\\录入数据读取模板.xls').sheet_by_name('Sheet1') 
                zhejiu_table = xlrd.open_workbook('E:\\A.常用文件夹\\驻点\\yssj\\折旧方法设置新国.xls').sheet_by_name('折旧方法设置') 

                temp_table_0101 = xlrd.open_workbook('E:\\A.常用文件夹\\驻点\\yssj\\新资产导入表\\A01010000房屋类.xls', formatting_info = True)
                temp_table_0102 = xlrd.open_workbook('E:\\A.常用文件夹\\驻点\\yssj\\新资产导入表\\A01020000构筑物类.xls', formatting_info = True)
                temp_table_0201 = xlrd.open_workbook('E:\\A.常用文件夹\\驻点\\yssj\\新资产导入表\\A02010000信息化设备类_设备.xls', formatting_info = True)
                temp_table_0203 = xlrd.open_workbook('E:\\A.常用文件夹\\驻点\\yssj\\新资产导入表\\A02030000车辆类_设备.xls', formatting_info = True)
                temp_table_0200 = xlrd.open_workbook('E:\\A.常用文件夹\\驻点\\yssj\\新资产导入表\\A02000000设备类（除车辆类，信息化设备）.xls', formatting_info = True)
                temp_table_0300 = xlrd.open_workbook('E:\\A.常用文件夹\\驻点\\yssj\\新资产导入表\\A03000000文物及陈列品类.xls', formatting_info = True)
                temp_table_0400 = xlrd.open_workbook('E:\\A.常用文件夹\\驻点\\yssj\\新资产导入表\\A04000000图书和档案类.xls', formatting_info = True)
                temp_table_0500 = xlrd.open_workbook('E:\\A.常用文件夹\\驻点\\yssj\\新资产导入表\\A05000000家具、用具类和装具类.xls', formatting_info = True)
                temp_table_0600 = xlrd.open_workbook('E:\\A.常用文件夹\\驻点\\yssj\\新资产导入表\\A06000000特种动植物类.xls', formatting_info = True)
                temp_table_0804 = xlrd.open_workbook('E:\\A.常用文件夹\\驻点\\yssj\\新资产导入表\\A08040000土地使用权类.xls', formatting_info = True)
                temp_table_0800 = xlrd.open_workbook('E:\\A.常用文件夹\\驻点\\yssj\\新资产导入表\\A08000000专利等无形类.xls', formatting_info = True)
            except Exception as e:
                self.result_data_Text.insert(END,e)
                self.result_data_Text.insert(END,"请检查文件路径是否填写正确\n")
                self.result_data_Text.insert(END,"————————————————————————————————————————————————————————————————\n")
                sys.exit()

            new_table_0101 = xlutils.copy.copy(temp_table_0101)
            new_table_0102 = xlutils.copy.copy(temp_table_0102)
            new_table_0201 = xlutils.copy.copy(temp_table_0201)        
            new_table_0203 = xlutils.copy.copy(temp_table_0203)
            new_table_0200 = xlutils.copy.copy(temp_table_0200)
            new_table_0300 = xlutils.copy.copy(temp_table_0300)
            new_table_0400 = xlutils.copy.copy(temp_table_0400)
            new_table_0500 = xlutils.copy.copy(temp_table_0500)
            new_table_0600 = xlutils.copy.copy(temp_table_0600)
            new_table_0804 = xlutils.copy.copy(temp_table_0804)
            new_table_0800 = xlutils.copy.copy(temp_table_0800)

            st_0101 = new_table_0101.get_sheet(0) 
            st_0102 = new_table_0102.get_sheet(0)
            st_0201 = new_table_0201.get_sheet(0)         
            st_0203 = new_table_0203.get_sheet(0) 
            st_0200 = new_table_0200.get_sheet(0) 
            st_0300 = new_table_0300.get_sheet(0) 
            st_0400 = new_table_0400.get_sheet(0) 
            st_0500 = new_table_0500.get_sheet(0) 
            st_0600 = new_table_0600.get_sheet(0) 
            st_0804 = new_table_0804.get_sheet(0)
            st_0800 = new_table_0800.get_sheet(0) 
            
            new_table_row_0101 = 2
            new_table_row_0102 = 2
            new_table_row_0201 = 2        
            new_table_row_0203 = 2
            new_table_row_0200 = 2
            new_table_row_0300 = 2
            new_table_row_0400 = 2
            new_table_row_0500 = 2
            new_table_row_0600 = 2
            new_table_row_0804 = 2
            new_table_row_0800 = 2

            nRows = org_table.nrows
            zhejiu_nRows = zhejiu_table.nrows
            self.result_data_Text.insert(END,"读取完成！\n")
            self.result_data_Text.insert(END,"————————————————————————————————————————————————————————————————\n")
            self.result_data_Text.insert(END,"开始遍历数据......\n")
            self.result_data_Text.insert(END,"————————————————————————————————————————————————————————————————\n")
            for i in range(1, nRows):  # 循环行数
                row_vals = org_table.row_values(i)
                type = str(row_vals[5])
                zhejiu_State = ""
                user_years = ""
                zichanlaiyuan = ""
                zhejiu_fun = ""
                match str(row_vals[20]):
                    case "1":
                        zichanlaiyuan = "新购"
                    case "2":
                        zichanlaiyuan = "调拨"
                    case "4":
                        zichanlaiyuan = "捐赠"
                    case "10":
                        zichanlaiyuan = "其他"
                jingfeilaiyuan = ""
                match str(row_vals[20]):
                    case "1":
                        jingfeilaiyuan = "财政拨款"
                    case "2":
                        jingfeilaiyuan = "调拨"
                    case "4":
                        jingfeilaiyuan = "捐赠"
                    case "10":
                        jingfeilaiyuan = "其他资金"
                for i in range(1, zhejiu_nRows): 
                    zhejiu_row_vals = zhejiu_table.row_values(i)
                    zhejiu_type = str(zhejiu_row_vals[0])
                    if(type == zhejiu_type):
                        zhejiu_State = str(zhejiu_row_vals[2])
                        user_years = str(zhejiu_row_vals[3])
                        if(str(zhejiu_row_vals[2]) == '不提折旧'):
                            zhejiu_fun = '不提折旧'
                        else:
                            if("{:.2f}".format(float(row_vals[3] - float(row_vals[4]))) == '0.00'):
                                zhejiu_fun = '已完成折旧'
                            else:
                                zhejiu_fun = '提折旧'
                if(type.startswith("A0101")):
                    st_0101.write(new_table_row_0101, 0, str(row_vals[0])) # 资产编号
                    st_0101.write(new_table_row_0101, 4, type) # 分类代码
                    st_0101.write(new_table_row_0101, 5, str(row_vals[2])) # 资产名称
                    st_0101.write(new_table_row_0101, 6, 1 if row_vals[24] == '' else "{:.2f}".format(float(row_vals[24]))) # 建筑面积
                    st_0101.write(new_table_row_0101, 7, str(row_vals[29])) # 计量单位
                    st_0101.write(new_table_row_0101, 10, str(row_vals[10])) # 管理部门
                    st_0101.write(new_table_row_0101, 11, str(row_vals[27])) # 管理人
                    st_0101.write(new_table_row_0101, 12, str(row_vals[10])) # 使用部门
                    st_0101.write(new_table_row_0101, 13, str(row_vals[27])) # 使用人
                    st_0101.write(new_table_row_0101, 14, "需确认") # 配置批准单位
                    st_0101.write(new_table_row_0101, 15, zichanlaiyuan) # 取得方式
                    st_0101.write(new_table_row_0101, 16, "需确认") # 建筑结构
                    st_0101.write(new_table_row_0101, 17, "需确认") # 采购组织形式
                    st_0101.write(new_table_row_0101, 20, xlrd.xldate_as_datetime(row_vals[9],0), datastyle) # 取得日期
                    st_0101.write(new_table_row_0101, 21, xlrd.xldate_as_datetime(row_vals[9],0), datastyle_year) # 建设年份
                    st_0101.write(new_table_row_0101, 22, str(row_vals[31])) # 坐落位置                
                    st_0101.write(new_table_row_0101, 23, "需确认") # 资产用途
                    st_0101.write(new_table_row_0101, 24, "需确认") # 层数
                    st_0101.write(new_table_row_0101, 25, "在用" if str(row_vals[11]) == '1' else "不在用") # 资产状态
                    st_0101.write(new_table_row_0101, 27, "否") # 是否共享共用
                    st_0101.write(new_table_row_0101, 28, "单位") # 使用责任主体
                    st_0101.write(new_table_row_0101, 29, "需确认") # 占地面积
                    st_0101.write(new_table_row_0101, 30, "需确认") # 地上建筑面积
                    st_0101.write(new_table_row_0101, 33, "需确认") # 房屋资产账中是否包含土地使用权
                    st_0101.write(new_table_row_0101, 34, "需确认") # 房屋资产账中包含的土地使用权面积
                    st_0101.write(new_table_row_0101, 35, "需确认") # 产权形式
                    st_0101.write(new_table_row_0101, 36, "需确认") # 权属证明
                    st_0101.write(new_table_row_0101, 37, str(row_vals[13])) # 权属证号
                    st_0101.write(new_table_row_0101, 38, xlrd.xldate_as_datetime(row_vals[14],0), datastyle) # 发证日期
                    st_0101.write(new_table_row_0101, 39, "国有") # 权属性质
                    st_0101.write(new_table_row_0101, 40, "需确认") # 权属统一登记情况
                    st_0101.write(new_table_row_0101, 41, "需确认") # 权属面积
                    st_0101.write(new_table_row_0101, 42, "需确认") # 证载用途
                    st_0101.write(new_table_row_0101, 43, "{:.2f}".format(float(row_vals[3]))) # 资产原值
                    st_0101.write(new_table_row_0101, 44, "{:.2f}".format(float(row_vals[4]))) # 累计折旧
                    st_0101.write(new_table_row_0101, 45, "{:.2f}".format(float(row_vals[3] - float(row_vals[4])))) # 账面净值
                    st_0101.write(new_table_row_0101, 46, "历史成本") # 价值类型
                    st_0101.write(new_table_row_0101, 52, zhejiu_State) # 折旧/摊销方法
                    st_0101.write(new_table_row_0101, 53, user_years) # 折旧/摊销年限
                    st_0101.write(new_table_row_0101, 56, zhejiu_fun) # 折旧/摊销状态
                    st_0101.write(new_table_row_0101, 58, "已入账") # 财务入账状态
                    st_0101.write(new_table_row_0101, 59, 1 if str(row_vals[12]) == '' else str(row_vals[12])) # 记账凭证号
                    st_0101.write(new_table_row_0101, 60, xlrd.xldate_as_datetime(row_vals[28],0), datastyle) # 记账日期
                    st_0101.write(new_table_row_0101, 61, jingfeilaiyuan) # 经费来源
                    st_0101.write(new_table_row_0101, 62, "1") # 项目代码
                    st_0101.write(new_table_row_0101, 65, "固定资产") # 单位会计科目
                    new_table_row_0101 = new_table_row_0101 + 1
                    # st_0101.write(new_table_row_0101, 0, str(row_vals[0])) # 资产编号
                    # st_0101.write(new_table_row_0101, 4, type) # 分类代码
                    # st_0101.write(new_table_row_0101, 5, str(row_vals[2])) # 资产名称
                    # st_0101.write(new_table_row_0101, 6, 1 if row_vals[24] == '' else "{:.2f}".format(float(row_vals[24]))) # 建筑面积
                    # st_0101.write(new_table_row_0101, 7, str(row_vals[29])) # 计量单位
                    # st_0101.write(new_table_row_0101, 10, str(row_vals[10])) # 管理部门
                    # st_0101.write(new_table_row_0101, 11, str(row_vals[27])) # 管理人
                    # st_0101.write(new_table_row_0101, 12, str(row_vals[10])) # 使用部门
                    # st_0101.write(new_table_row_0101, 13, str(row_vals[27])) # 使用人
                    # st_0101.write(new_table_row_0101, 14, "财政部门") # 配置批准单位
                    # st_0101.write(new_table_row_0101, 15, zichanlaiyuan) # 取得方式
                    # st_0101.write(new_table_row_0101, 16, "钢混结构") # 建筑结构
                    # st_0101.write(new_table_row_0101, 17, "单位集中采购") # 采购组织形式
                    # st_0101.write(new_table_row_0101, 20, xlrd.xldate_as_datetime(row_vals[9],0), datastyle) # 取得日期
                    # st_0101.write(new_table_row_0101, 21, xlrd.xldate_as_datetime(row_vals[9],0), datastyle_year) # 建设年份
                    # st_0101.write(new_table_row_0101, 22, str(row_vals[31])) # 坐落位置                
                    # st_0101.write(new_table_row_0101, 23, "办公") # 资产用途
                    # st_0101.write(new_table_row_0101, 24, "1") # 层数
                    # st_0101.write(new_table_row_0101, 25, "在用" if str(row_vals[11]) == '1' else "不在用") # 资产状态
                    # st_0101.write(new_table_row_0101, 27, "否") # 是否共享共用
                    # st_0101.write(new_table_row_0101, 28, "单位") # 使用责任主体
                    # st_0101.write(new_table_row_0101, 29, 1 if row_vals[24] == '' else "{:.2f}".format(float(row_vals[24]))) # 占地面积
                    # st_0101.write(new_table_row_0101, 30, 1 if row_vals[24] == '' else "{:.2f}".format(float(row_vals[24]))) # 地上建筑面积
                    # st_0101.write(new_table_row_0101, 33, "是") # 房屋资产账中是否包含土地使用权
                    # st_0101.write(new_table_row_0101, 34, 1 if row_vals[24] == '' else "{:.2f}".format(float(row_vals[24]))) # 房屋资产账中包含的土地使用权面积
                    # st_0101.write(new_table_row_0101, 35, "有产权证") # 产权形式
                    # st_0101.write(new_table_row_0101, 36, "暂无") # 权属证明
                    # st_0101.write(new_table_row_0101, 37, str(row_vals[13])) # 权属证号
                    # st_0101.write(new_table_row_0101, 38, xlrd.xldate_as_datetime(row_vals[14],0), datastyle) # 发证日期
                    # st_0101.write(new_table_row_0101, 39, "国有") # 权属性质
                    # st_0101.write(new_table_row_0101, 40, "已登记") # 权属统一登记情况
                    # st_0101.write(new_table_row_0101, 41, 1 if row_vals[24] == '' else "{:.2f}".format(float(row_vals[24]))) # 权属面积
                    # st_0101.write(new_table_row_0101, 42, "办公及业务用地") # 证载用途
                    # st_0101.write(new_table_row_0101, 43, "{:.2f}".format(float(row_vals[3]))) # 资产原值
                    # st_0101.write(new_table_row_0101, 44, "{:.2f}".format(float(row_vals[4]))) # 累计折旧
                    # st_0101.write(new_table_row_0101, 45, "{:.2f}".format(float(row_vals[3] - float(row_vals[4])))) # 账面净值
                    # st_0101.write(new_table_row_0101, 46, "历史成本") # 价值类型
                    # st_0101.write(new_table_row_0101, 52, zhejiu_State) # 折旧/摊销方法
                    # st_0101.write(new_table_row_0101, 53, user_years) # 折旧/摊销年限
                    # st_0101.write(new_table_row_0101, 56, zhejiu_fun) # 折旧/摊销状态
                    # st_0101.write(new_table_row_0101, 58, "已入账") # 财务入账状态
                    # st_0101.write(new_table_row_0101, 59, 1 if str(row_vals[12]) == '' else str(row_vals[12])) # 记账凭证号
                    # st_0101.write(new_table_row_0101, 60, xlrd.xldate_as_datetime(row_vals[28],0), datastyle) # 记账日期
                    # st_0101.write(new_table_row_0101, 61, jingfeilaiyuan) # 经费来源
                    # st_0101.write(new_table_row_0101, 62, "1") # 项目代码
                    # st_0101.write(new_table_row_0101, 65, "固定资产") # 单位会计科目
                elif(type.startswith("A0102")):
                    st_0102.write(new_table_row_0102, 0, str(row_vals[0])) # 资产编号
                    st_0102.write(new_table_row_0102, 4, type) # 分类代码
                    st_0102.write(new_table_row_0102, 5, str(row_vals[2])) # 资产名称
                    st_0102.write(new_table_row_0102, 6, 1 if row_vals[24] == '' else "{:.2f}".format(float(row_vals[24]))) # 建筑面积
                    st_0102.write(new_table_row_0102, 7, str(row_vals[29])) # 计量单位
                    st_0102.write(new_table_row_0102, 10, str(row_vals[10])) # 管理部门
                    st_0102.write(new_table_row_0102, 11, str(row_vals[27])) # 管理人
                    st_0102.write(new_table_row_0102, 12, str(row_vals[10])) # 使用部门
                    st_0102.write(new_table_row_0102, 13, str(row_vals[27])) # 使用人
                    st_0102.write(new_table_row_0102, 14, "财政部门") # 配置批准单位
                    st_0102.write(new_table_row_0102, 15, zichanlaiyuan) # 取得方式
                    st_0102.write(new_table_row_0102, 16, xlrd.xldate_as_datetime(row_vals[9],0), datastyle) # 取得日期
                    st_0102.write(new_table_row_0102, 17, "单位集中采购") # 采购组织形式
                    st_0102.write(new_table_row_0102, 18, "在用" if str(row_vals[11]) == '1' else "不在用") # 资产状态
                    st_0102.write(new_table_row_0102, 19, "单位") # 使用责任主体
                    st_0102.write(new_table_row_0102, 20, "否") # 是否共享共用
                    st_0102.write(new_table_row_0102, 21, xlrd.xldate_as_datetime(row_vals[9],0), datastyle) # 投入使用日期
                    st_0102.write(new_table_row_0102, 22, str(row_vals[31])) # 坐落位置
                    st_0102.write(new_table_row_0102, 23, "固定资产") # 单位会计科目
                    st_0102.write(new_table_row_0102, 24, "1") # 项目代码
                    st_0102.write(new_table_row_0102, 25, "历史成本") # 价值类型
                    st_0102.write(new_table_row_0102, 26, "{:.2f}".format(float(row_vals[3]))) # 资产原值
                    st_0102.write(new_table_row_0102, 30, "已入账") # 财务入账状态
                    st_0102.write(new_table_row_0102, 31, xlrd.xldate_as_datetime(row_vals[28],0), datastyle) # 记账日期
                    st_0102.write(new_table_row_0102, 32, 1 if str(row_vals[12]) == '' else str(row_vals[12])) # 记账凭证号
                    st_0102.write(new_table_row_0102, 33, zhejiu_fun) # 折旧/摊销状态
                    st_0102.write(new_table_row_0102, 37, user_years) # 折旧/摊销年限
                    st_0102.write(new_table_row_0102, 38, zhejiu_State) # 折旧/摊销方法
                    st_0102.write(new_table_row_0102, 39, "{:.2f}".format(float(row_vals[4]))) # 累计折旧
                    st_0102.write(new_table_row_0102, 40, "{:.2f}".format(float(row_vals[3] - float(row_vals[4])))) # 账面净值
                    new_table_row_0102 = new_table_row_0102 + 1
                elif(type.startswith("A0201")):
                    st_0201.write(new_table_row_0201, 0, str(row_vals[0])) # 资产编号
                    st_0201.write(new_table_row_0201, 4, type) # 分类代码
                    st_0201.write(new_table_row_0201, 5, str(row_vals[2])) # 资产名称
                    st_0201.write(new_table_row_0201, 6, str(row_vals[29])) # 计量单位
                    st_0201.write(new_table_row_0201, 7, str(row_vals[10])) # 管理部门
                    st_0201.write(new_table_row_0201, 8, str(row_vals[27])) # 使用人
                    st_0201.write(new_table_row_0201, 9, str(row_vals[27])) # 管理人
                    st_0201.write(new_table_row_0201, 12, str(row_vals[10])) # 使用部门
                    st_0201.write(new_table_row_0201, 13, "财政部门") # 配置批准单位
                    st_0201.write(new_table_row_0201, 14, "单位集中采购") # 采购组织形式
                    st_0201.write(new_table_row_0201, 19, "在用" if str(row_vals[11]) == '1' else "不在用") # 资产状态
                    st_0201.write(new_table_row_0201, 20, zichanlaiyuan) # 取得方式
                    st_0201.write(new_table_row_0201, 21, xlrd.xldate_as_datetime(row_vals[9],0), datastyle) # 取得日期
                    st_0201.write(new_table_row_0201, 22, "单位") # 使用责任主体
                    st_0201.write(new_table_row_0201, 23, "国产" if str(row_vals[18]) == '' or str(row_vals[18]).startswith('无') else str(row_vals[18])) # 品牌
                    st_0201.write(new_table_row_0201, 24, "常规" if str(row_vals[17]) == '' or str(row_vals[17]).startswith('无') else str(row_vals[17])) # 规格型号
                    st_0201.write(new_table_row_0201, 25, xlrd.xldate_as_datetime(row_vals[9],0), datastyle) # 投入使用日期
                    st_0201.write(new_table_row_0201, 26, "已入账") # 财务入账状态
                    st_0201.write(new_table_row_0201, 27, "否") # 是否共享共用
                    st_0201.write(new_table_row_0201, 32, "办公") # 资产用途
                    st_0201.write(new_table_row_0201, 33, str(row_vals[21])) # 存放地点
                    st_0201.write(new_table_row_0201, 36, "固定资产") # 单位会计科目
                    st_0201.write(new_table_row_0201, 37, "{:.2f}".format(float(row_vals[3]))) # 资产原值
                    st_0201.write(new_table_row_0201, 39, 1 if str(row_vals[12]) == '' else str(row_vals[12])) # 记账凭证号
                    st_0201.write(new_table_row_0201, 40, user_years) # 折旧/摊销年限
                    st_0201.write(new_table_row_0201, 42, "{:.2f}".format(float(row_vals[4]))) # 累计折旧
                    st_0201.write(new_table_row_0201, 43, "{:.2f}".format(float(row_vals[3] - float(row_vals[4])))) # 账面净值
                    st_0201.write(new_table_row_0201, 45, "1") # 项目代码
                    st_0201.write(new_table_row_0201, 46, "历史成本") # 价值类型
                    st_0201.write(new_table_row_0201, 49, xlrd.xldate_as_datetime(row_vals[28],0), datastyle) # 记账日期
                    st_0201.write(new_table_row_0201, 50, zhejiu_fun) # 折旧/摊销状态
                    st_0201.write(new_table_row_0201, 51, zhejiu_State) # 折旧/摊销方法
                    st_0201.write(new_table_row_0201, 52, str(row_vals[30])) # 备注
                    new_table_row_0201 = new_table_row_0201 + 1    
                elif(type.startswith("A0203")):
                    st_0203.write(new_table_row_0203, 0, str(row_vals[0])) # 资产编号
                    st_0203.write(new_table_row_0203, 4, type) # 分类代码
                    st_0203.write(new_table_row_0203, 5, str(row_vals[2])) # 资产名称
                    st_0203.write(new_table_row_0203, 6, str(row_vals[10])) # 使用部门
                    st_0203.write(new_table_row_0203, 7, "{:.2f}".format(float(row_vals[3]))) # 资产原值
                    st_0203.write(new_table_row_0203, 8, "{:.2f}".format(float(row_vals[4]))) # 累计折旧
                    st_0203.write(new_table_row_0203, 9, "{:.2f}".format(float(row_vals[3] - float(row_vals[4])))) # 账面净值
                    st_0203.write(new_table_row_0203, 10, zhejiu_State) # 折旧/摊销方法
                    st_0203.write(new_table_row_0203, 11, str(row_vals[29])) # 计量单位
                    st_0203.write(new_table_row_0203, 12, str(row_vals[27])) # 使用人  
                    st_0203.write(new_table_row_0203, 14, str(row_vals[10])) # 管理部门
                    st_0203.write(new_table_row_0203, 15, str(row_vals[27])) # 管理人  
                    st_0203.write(new_table_row_0203, 16, "单位") # 使用责任主体
                    st_0203.write(new_table_row_0203, 18, "在编") # 资产编制情况
                    st_0203.write(new_table_row_0203, 19, "需确认") # 车辆类型
                    st_0203.write(new_table_row_0203, 20, "本单位") # 采购实施单位
                    st_0203.write(new_table_row_0203, 21, xlrd.xldate_as_datetime(row_vals[9],0), datastyle) # 取得日期
                    st_0203.write(new_table_row_0203, 22, "财政部门") # 配置批准单位
                    st_0203.write(new_table_row_0203, 23, "单位集中采购") # 采购组织形式
                    st_0203.write(new_table_row_0203, 24, "是") # 是否统一标志
                    st_0203.write(new_table_row_0203, 25, xlrd.xldate_as_datetime(row_vals[9],0), datastyle) # 出厂日期
                    st_0203.write(new_table_row_0203, 26, zichanlaiyuan) # 取得方式
                    st_0203.write(new_table_row_0203, 28, xlrd.xldate_as_datetime(row_vals[9],0), datastyle) # 投入使用日期
                    st_0203.write(new_table_row_0203, 29, "否") # 是否共享共用
                    st_0203.write(new_table_row_0203, 30, "需确认") # 车辆行驶证
                    st_0203.write(new_table_row_0203, 31, "需确认") # 车辆识别代码
                    st_0203.write(new_table_row_0203, 32, "在用" if str(row_vals[11]) == '1' else "不在用") # 车辆状态
                    st_0203.write(new_table_row_0203, 34, "需确认") # 排放标准
                    st_0203.write(new_table_row_0203, 35, "国产" if str(row_vals[18]) == '' or str(row_vals[18]).startswith('无') else str(row_vals[18])) # 厂牌型号
                    st_0203.write(new_table_row_0203, 36, "常规" if str(row_vals[17]) == '' or str(row_vals[17]).startswith('无') else str(row_vals[17])) # 规格型号
                    st_0203.write(new_table_row_0203, 37, str(row_vals[19])) # 车辆用途
                    st_0203.write(new_table_row_0203, 38, "在用" if str(row_vals[11]) == '1' else "不在用") # 资产状态
                    st_0203.write(new_table_row_0203, 41, str(row_vals[22])) # 车牌号
                    st_0203.write(new_table_row_0203, 42, "需确认") # 动力类型
                    st_0203.write(new_table_row_0203, 44, xlrd.xldate_as_datetime(row_vals[9],0), datastyle) # 注册日期
                    st_0203.write(new_table_row_0203, 46, str(row_vals[21])) # 存放地点
                    st_0203.write(new_table_row_0203, 47, "需确认") # 汽车排气量
                    st_0203.write(new_table_row_0203, 51, "是") # 是否安装定位终端
                    st_0203.write(new_table_row_0203, 52, "固定资产") # 单位会计科目
                    st_0203.write(new_table_row_0203, 53, 1 if str(row_vals[12]) == '' else str(row_vals[12])) # 凭证号
                    st_0203.write(new_table_row_0203, 54, "1") # 项目代码
                    st_0203.write(new_table_row_0203, 55, "历史成本") # 价值类型
                    st_0203.write(new_table_row_0203, 58, zhejiu_fun) # 折旧/摊销状态
                    st_0203.write(new_table_row_0203, 59, user_years) # 折旧/摊销年限
                    st_0203.write(new_table_row_0203, 60, xlrd.xldate_as_datetime(row_vals[28],0), datastyle) # 记账日期
                    st_0203.write(new_table_row_0203, 61, "已入账") # 财务入账状态
                    new_table_row_0203 = new_table_row_0203 + 1
                elif(type.startswith("A02")):
                    st_0200.write(new_table_row_0200, 0, str(row_vals[0])) # 资产编号
                    st_0200.write(new_table_row_0200, 4, type) # 分类代码
                    st_0200.write(new_table_row_0200, 5, str(row_vals[2])) # 资产名称
                    st_0200.write(new_table_row_0200, 6, str(row_vals[29])) # 计量单位
                    st_0200.write(new_table_row_0200, 7, str(row_vals[10])) # 管理部门
                    st_0200.write(new_table_row_0200, 8, str(row_vals[27])) # 使用人
                    st_0200.write(new_table_row_0200, 9, str(row_vals[27])) # 管理人
                    st_0200.write(new_table_row_0200, 12, str(row_vals[10])) # 使用部门
                    st_0200.write(new_table_row_0200, 13, "财政部门") # 配置批准单位
                    st_0200.write(new_table_row_0200, 14, "单位集中采购") # 采购组织形式
                    st_0200.write(new_table_row_0200, 19, "在用" if str(row_vals[11]) == '1' else "不在用") # 资产状态
                    st_0200.write(new_table_row_0200, 20, zichanlaiyuan) # 取得方式
                    st_0200.write(new_table_row_0200, 21, xlrd.xldate_as_datetime(row_vals[9],0), datastyle) # 取得日期
                    st_0200.write(new_table_row_0200, 22, "单位") # 使用责任主体
                    st_0200.write(new_table_row_0200, 23, "国产" if str(row_vals[18]) == '' or str(row_vals[18]).startswith('无') else str(row_vals[18])) # 品牌
                    st_0200.write(new_table_row_0200, 24, "常规" if str(row_vals[17]) == '' or str(row_vals[17]).startswith('无') else str(row_vals[17])) # 规格型号
                    st_0200.write(new_table_row_0200, 25, xlrd.xldate_as_datetime(row_vals[9],0), datastyle) # 投入使用日期
                    st_0200.write(new_table_row_0200, 26, "已入账") # 财务入账状态
                    st_0200.write(new_table_row_0200, 27, "否") # 是否共享共用
                    st_0200.write(new_table_row_0200, 30, "办公") # 资产用途
                    st_0200.write(new_table_row_0200, 31, str(row_vals[21])) # 存放地点
                    st_0200.write(new_table_row_0200, 34, "固定资产") # 单位会计科目
                    st_0200.write(new_table_row_0200, 35, "{:.2f}".format(float(row_vals[3]))) # 资产原值
                    st_0200.write(new_table_row_0200, 37, 1 if str(row_vals[12]) == '' else str(row_vals[12])) # 凭证号
                    st_0200.write(new_table_row_0200, 38, user_years) # 折旧/摊销年限
                    st_0200.write(new_table_row_0200, 40, "{:.2f}".format(float(row_vals[4]))) # 累计折旧
                    st_0200.write(new_table_row_0200, 41, "{:.2f}".format(float(row_vals[3] - float(row_vals[4])))) # 账面净值
                    st_0200.write(new_table_row_0200, 43, "1") # 项目代码
                    st_0200.write(new_table_row_0200, 44, "历史成本") # 价值类型
                    st_0200.write(new_table_row_0200, 47, xlrd.xldate_as_datetime(row_vals[28],0), datastyle) # 记账日期
                    st_0200.write(new_table_row_0200, 48, zhejiu_fun) # 折旧/摊销状态
                    st_0200.write(new_table_row_0200, 49, zhejiu_State) # 折旧/摊销方法
                    st_0200.write(new_table_row_0200, 50, str(row_vals[30])) # 备注
                    new_table_row_0200 = new_table_row_0200 + 1
                elif(type.startswith("A03")):
                    st_0300.write(new_table_row_0300, 0, str(row_vals[0])) # 资产编号
                    st_0300.write(new_table_row_0300, 2, type) # 分类代码
                    st_0300.write(new_table_row_0300, 4, str(row_vals[2])) # 资产名称
                    st_0300.write(new_table_row_0300, 5, str(row_vals[10])) # 使用部门
                    st_0300.write(new_table_row_0300, 6, "{:.2f}".format(float(row_vals[3]))) # 价值
                    st_0300.write(new_table_row_0300, 7, str(row_vals[29])) # 计量单位
                    st_0300.write(new_table_row_0300, 8, str(row_vals[27])) # 使用人  
                    st_0300.write(new_table_row_0300, 9, "在用" if str(row_vals[11]) == '1' else "不在用") # 资产状态
                    st_0300.write(new_table_row_0300, 11, "自用") # 使用方向
                    st_0300.write(new_table_row_0300, 12, xlrd.xldate_as_datetime(row_vals[9],0), datastyle) # 取得日期
                    st_0300.write(new_table_row_0300, 14, "历史成本") # 价值类型
                    st_0300.write(new_table_row_0300, 15, str(row_vals[30])) # 备注
                    st_0300.write(new_table_row_0300, 16, zichanlaiyuan) # 取得方式
                    st_0300.write(new_table_row_0300, 17, jingfeilaiyuan) # 经费来源
                    st_0300.write(new_table_row_0300, 18, 1 if str(row_vals[12]) == '' else str(row_vals[12])) # 凭证号
                    st_0300.write(new_table_row_0300, 20, xlrd.xldate_as_datetime(row_vals[28],0), datastyle) # 入账日期
                    st_0300.write(new_table_row_0300, 21, "政府集中采购") # 采购组织形式
                    st_0300.write(new_table_row_0300, 22, "{:.2f}".format(float(row_vals[4]))) # 累计折旧
                    st_0300.write(new_table_row_0300, 23, "{:.2f}".format(float(row_vals[3] - float(row_vals[4])))) # 账面净值
                    st_0300.write(new_table_row_0300, 24, zhejiu_State) # 折旧状态
                    st_0300.write(new_table_row_0300, 25, "文物级别") # 文物级别
                    st_0300.write(new_table_row_0300, 34, str(row_vals[21])) # 存放地点
                    st_0300.write(new_table_row_0300, 36, xlrd.xldate_as_datetime(row_vals[9],0), datastyle) # 投入使用日期
                    st_0300.write(new_table_row_0300, 37, "已入账") # 是否入账
                    new_table_row_0300 = new_table_row_0300 + 1
                elif(type.startswith("A04")):
                    st_0400.write(new_table_row_0400, 0, str(row_vals[0])) # 资产编号
                    st_0400.write(new_table_row_0400, 2, type) # 分类代码
                    st_0400.write(new_table_row_0400, 4, str(row_vals[2])) # 资产名称
                    st_0400.write(new_table_row_0400, 5, str(row_vals[10])) # 使用部门
                    st_0400.write(new_table_row_0400, 6, "{:.2f}".format(float(row_vals[3]))) # 价值
                    st_0400.write(new_table_row_0400, 7, str(row_vals[29])) # 计量单位
                    st_0400.write(new_table_row_0400, 8, str(row_vals[27])) # 使用人  
                    st_0400.write(new_table_row_0400, 9, "在用" if str(row_vals[11]) == '1' else "不在用") # 资产状态
                    st_0400.write(new_table_row_0400, 11, "自用") # 使用方向
                    st_0400.write(new_table_row_0400, 12, xlrd.xldate_as_datetime(row_vals[9],0), datastyle) # 取得日期
                    st_0400.write(new_table_row_0400, 14, "历史成本") # 价值类型
                    st_0400.write(new_table_row_0400, 15, str(row_vals[30])) # 备注
                    st_0400.write(new_table_row_0400, 16, zichanlaiyuan) # 取得方式
                    st_0400.write(new_table_row_0400, 17, jingfeilaiyuan) # 经费来源
                    st_0400.write(new_table_row_0400, 18, 1 if str(row_vals[12]) == '' else str(row_vals[12])) # 凭证号
                    st_0400.write(new_table_row_0400, 20, xlrd.xldate_as_datetime(row_vals[28],0), datastyle) # 入账日期
                    st_0400.write(new_table_row_0400, 21, "政府集中采购") # 采购组织形式
                    st_0400.write(new_table_row_0400, 22, "{:.2f}".format(float(row_vals[4]))) # 累计折旧
                    st_0400.write(new_table_row_0400, 23, "{:.2f}".format(float(row_vals[3] - float(row_vals[4])))) # 账面净值
                    st_0400.write(new_table_row_0400, 24, zhejiu_State) # 折旧状态
                    st_0400.write(new_table_row_0400, 25, "图书册数") # 图书册数
                    st_0400.write(new_table_row_0400, 35, str(row_vals[21])) # 存放地点
                    st_0400.write(new_table_row_0400, 38, xlrd.xldate_as_datetime(row_vals[9],0), datastyle) # 投入使用日期
                    st_0400.write(new_table_row_0400, 39, "已入账") # 是否入账
                    new_table_row_0400 = new_table_row_0400 + 1
                elif(type.startswith("A05")):
                    st_0500.write(new_table_row_0500, 0, str(row_vals[0])) # 资产编号
                    st_0500.write(new_table_row_0500, 4, type) # 分类代码
                    st_0500.write(new_table_row_0500, 5, "1") # 项目代码
                    st_0500.write(new_table_row_0500, 6, str(row_vals[2])) # 资产名称
                    st_0500.write(new_table_row_0500, 7, str(row_vals[10])) # 使用部门
                    st_0500.write(new_table_row_0500, 8, "历史成本") # 价值类型
                    st_0500.write(new_table_row_0500, 9, "{:.2f}".format(float(row_vals[3]))) # 资产原值
                    st_0500.write(new_table_row_0500, 10, str(row_vals[29])) # 计量单位
                    st_0500.write(new_table_row_0500, 11, "{:.2f}".format(float(row_vals[4]))) # 累计折旧
                    st_0500.write(new_table_row_0500, 12, zhejiu_State) # 折旧/摊销方法
                    st_0500.write(new_table_row_0500, 15, str(row_vals[27])) # 使用人
                    st_0500.write(new_table_row_0500, 16, 1 if str(row_vals[12]) == '' else str(row_vals[12])) # 凭证号
                    st_0500.write(new_table_row_0500, 18, "在用" if str(row_vals[11]) == '1' else "不在用") # 资产状态
                    st_0500.write(new_table_row_0500, 19, "办公") # 资产用途
                    st_0500.write(new_table_row_0500, 20, "1") # 数量
                    st_0500.write(new_table_row_0500, 22, str(row_vals[10])) # 管理部门
                    st_0500.write(new_table_row_0500, 23, str(row_vals[27])) # 管理人
                    st_0500.write(new_table_row_0500, 24, "财政部门") # 配置批准部门
                    st_0500.write(new_table_row_0500, 25, zichanlaiyuan) # 取得方式
                    st_0500.write(new_table_row_0500, 26, xlrd.xldate_as_datetime(row_vals[9],0), datastyle) # 取得日期
                    st_0500.write(new_table_row_0500, 27, "单位集中采购") # 采购组织形式
                    st_0500.write(new_table_row_0500, 28, "单位") # 使用责任主体
                    st_0500.write(new_table_row_0500, 29, xlrd.xldate_as_datetime(row_vals[9],0), datastyle) # 投入使用日期
                    st_0500.write(new_table_row_0500, 30, str(row_vals[21])) # 存放地点
                    st_0500.write(new_table_row_0500, 31, "否") # 是否共享共用
                    st_0500.write(new_table_row_0500, 32, "国产" if str(row_vals[18]) == '' or str(row_vals[18]).startswith('无') else str(row_vals[18])) # 品牌
                    st_0500.write(new_table_row_0500, 33, "常规" if str(row_vals[17]) == '' or str(row_vals[17]).startswith('无') else str(row_vals[17])) # 质料或规格
                    st_0500.write(new_table_row_0500, 34, "否") # 单位会计科目
                    st_0500.write(new_table_row_0500, 35, user_years) # 折旧/摊销年限
                    st_0500.write(new_table_row_0500, 38, "{:.2f}".format(float(row_vals[3] - float(row_vals[4])))) # 账面净值
                    st_0500.write(new_table_row_0500, 39, zhejiu_fun) # 折旧/摊销状态
                    st_0500.write(new_table_row_0500, 40, xlrd.xldate_as_datetime(row_vals[28],0), datastyle) # 记账日期
                    st_0500.write(new_table_row_0500, 41, "已入账") # 财务入账状态
                    new_table_row_0500 = new_table_row_0500 + 1
                elif(type.startswith("A060")):
                    st_0600.write(new_table_row_0600, 0, str(row_vals[0])) # 资产编号
                    st_0600.write(new_table_row_0600, 2, type) # 分类代码
                    st_0600.write(new_table_row_0600, 4, str(row_vals[2])) # 资产名称
                    st_0600.write(new_table_row_0600, 5, str(row_vals[10])) # 使用部门
                    st_0600.write(new_table_row_0600, 6, "{:.2f}".format(float(row_vals[3]))) # 价值
                    st_0600.write(new_table_row_0600, 7, str(row_vals[29])) # 计量单位
                    st_0600.write(new_table_row_0600, 8, str(row_vals[27])) # 使用人  
                    st_0600.write(new_table_row_0600, 9, "在用" if str(row_vals[11]) == '1' else "不在用") # 资产状态
                    st_0600.write(new_table_row_0600, 11, "自用") # 使用方向
                    st_0600.write(new_table_row_0600, 12, xlrd.xldate_as_datetime(row_vals[9],0), datastyle) # 取得日期
                    st_0600.write(new_table_row_0600, 14, user_years) # 预期使用年限
                    st_0600.write(new_table_row_0600, 15, "历史成本") # 价值类型
                    st_0600.write(new_table_row_0600, 16, str(row_vals[30])) # 备注
                    st_0600.write(new_table_row_0600, 17, zichanlaiyuan) # 取得方式
                    st_0600.write(new_table_row_0600, 18, jingfeilaiyuan) # 经费来源
                    st_0600.write(new_table_row_0600, 19, 1 if str(row_vals[12]) == '' else str(row_vals[12])) # 凭证号
                    st_0600.write(new_table_row_0600, 21, xlrd.xldate_as_datetime(row_vals[28],0), datastyle) # 入账日期
                    st_0600.write(new_table_row_0600, 22, "政府集中采购") # 采购组织形式
                    st_0600.write(new_table_row_0600, 23, "{:.2f}".format(float(row_vals[4]))) # 累计折旧
                    st_0600.write(new_table_row_0600, 24, "{:.2f}".format(float(row_vals[3] - float(row_vals[4])))) # 账面净值
                    st_0600.write(new_table_row_0600, 25, zhejiu_State) # 折旧状态
                    st_0600.write(new_table_row_0600, 35, "已入账") # 是否入账
                    st_0600.write(new_table_row_0600, 37, str(row_vals[21])) # 存放地点
                    new_table_row_0600 = new_table_row_0600 + 1
                elif(type.startswith("A0804")):
                    st_0804.write(new_table_row_0804, 0, str(row_vals[0])) # 资产编号
                    st_0804.write(new_table_row_0804, 2, type) # 分类代码
                    st_0804.write(new_table_row_0804, 4, str(row_vals[2])) # 资产名称
                    st_0804.write(new_table_row_0804, 5, str(row_vals[10])) # 使用部门
                    st_0804.write(new_table_row_0804, 6, "{:.2f}".format(float(row_vals[3]))) # 价值
                    st_0804.write(new_table_row_0804, 7, str(row_vals[29])) # 计量单位
                    st_0804.write(new_table_row_0804, 8, str(row_vals[27])) # 使用人  
                    st_0804.write(new_table_row_0804, 9, "在用" if str(row_vals[11]) == '1' else "不在用") # 资产状态
                    st_0804.write(new_table_row_0804, 11, "自用") # 使用方向
                    st_0804.write(new_table_row_0804, 12, xlrd.xldate_as_datetime(row_vals[9],0), datastyle) # 取得日期
                    st_0804.write(new_table_row_0804, 14, "历史成本") # 价值类型
                    st_0804.write(new_table_row_0804, 15, str(row_vals[30])) # 备注
                    st_0804.write(new_table_row_0804, 16, zichanlaiyuan) # 取得方式
                    st_0804.write(new_table_row_0804, 17, jingfeilaiyuan) # 经费来源
                    st_0804.write(new_table_row_0804, 18, 1 if str(row_vals[12]) == '' else str(row_vals[12])) # 凭证号
                    st_0804.write(new_table_row_0804, 20, xlrd.xldate_as_datetime(row_vals[28],0), datastyle) # 入账日期
                    st_0804.write(new_table_row_0804, 21, "政府集中采购") # 采购组织形式
                    st_0804.write(new_table_row_0804, 22, "{:.2f}".format(float(row_vals[4]))) # 累计折旧
                    st_0804.write(new_table_row_0804, 23, "{:.2f}".format(float(row_vals[3] - float(row_vals[4])))) # 账面净值
                    st_0804.write(new_table_row_0804, 24, zhejiu_State) # 折旧状态
                    st_0804.write(new_table_row_0804, 28, "已入账") # 是否入账
                    st_0804.write(new_table_row_0804, 29, xlrd.xldate_as_datetime(row_vals[9],0), datastyle) # 投入使用日期
                    new_table_row_0804 = new_table_row_0804 + 1
                elif(type.startswith("A08")):
                    st_0800.write(new_table_row_0800, 0, str(row_vals[0])) # 资产编号
                    st_0800.write(new_table_row_0800, 2, type) # 分类代码
                    st_0800.write(new_table_row_0800, 4, str(row_vals[2])) # 资产名称
                    st_0800.write(new_table_row_0800, 5, str(row_vals[10])) # 使用部门
                    st_0800.write(new_table_row_0800, 6, "{:.2f}".format(float(row_vals[3]))) # 价值
                    st_0800.write(new_table_row_0800, 7, str(row_vals[29])) # 计量单位
                    st_0800.write(new_table_row_0800, 8, str(row_vals[27])) # 使用人  
                    st_0800.write(new_table_row_0800, 9, "在用" if str(row_vals[11]) == '1' else "不在用") # 资产状态
                    st_0800.write(new_table_row_0800, 10, "自用") # 使用方向
                    st_0800.write(new_table_row_0800, 11, xlrd.xldate_as_datetime(row_vals[9],0), datastyle) # 取得日期
                    st_0800.write(new_table_row_0800, 13, "历史成本") # 价值类型
                    st_0800.write(new_table_row_0800, 14, str(row_vals[30])) # 备注
                    st_0800.write(new_table_row_0800, 15, zichanlaiyuan) # 取得方式
                    st_0800.write(new_table_row_0800, 16, jingfeilaiyuan) # 经费来源
                    st_0800.write(new_table_row_0800, 17, 1 if str(row_vals[12]) == '' else str(row_vals[12])) # 凭证号
                    st_0800.write(new_table_row_0800, 19, xlrd.xldate_as_datetime(row_vals[28],0), datastyle) # 入账日期
                    st_0800.write(new_table_row_0800, 20, "政府集中采购") # 采购组织形式
                    st_0800.write(new_table_row_0800, 21, "{:.2f}".format(float(row_vals[4]))) # 累计折旧
                    st_0800.write(new_table_row_0800, 22, "{:.2f}".format(float(row_vals[3] - float(row_vals[4])))) # 账面净值
                    st_0800.write(new_table_row_0800, 23, zhejiu_State) # 折旧状态
                    st_0800.write(new_table_row_0800, 25, "授权证明") # 授权证明
                    st_0800.write(new_table_row_0800, 26, "授权证明号") # 授权证明号
                    st_0800.write(new_table_row_0800, 27, xlrd.xldate_as_datetime(row_vals[9],0), datastyle) # 投入使用日期
                    st_0800.write(new_table_row_0800, 29, "已入账") # 是否入账
                    new_table_row_0800 = new_table_row_0800 + 1
                else:
                    pass
            self.result_data_Text.insert(END,"遍历数据完成！\n")
            self.result_data_Text.insert(END,"————————————————————————————————————————————————————————————————\n")
            try:
                new_table_0101.save("E:\\A.常用文件夹\\驻点\\Python tool\\录入\\导出数据\\A01010000房屋类.xls")
                new_table_0102.save("E:\\A.常用文件夹\\驻点\\Python tool\\录入\\导出数据\\A01020000构筑物类.xls")
                new_table_0201.save("E:\\A.常用文件夹\\驻点\\Python tool\\录入\\导出数据\\A02010000信息化设备类_设备.xls")            
                new_table_0203.save("E:\\A.常用文件夹\\驻点\\Python tool\\录入\\导出数据\\A02030000车辆类_设备.xls")
                new_table_0200.save("E:\\A.常用文件夹\\驻点\\Python tool\\录入\\导出数据\\A02000000设备类（除车辆类，信息化设备）.xls")
                new_table_0300.save("E:\\A.常用文件夹\\驻点\\Python tool\\录入\\导出数据\\A03000000文物及陈列品类.xls")
                new_table_0400.save("E:\\A.常用文件夹\\驻点\\Python tool\\录入\\导出数据\\A04000000图书和档案类.xls")
                new_table_0500.save("E:\\A.常用文件夹\\驻点\\Python tool\\录入\\导出数据\\A05000000家具、用具类和装具类.xls")
                new_table_0600.save("E:\\A.常用文件夹\\驻点\\Python tool\\录入\\导出数据\\A06000000特种动植物类.xls")
                new_table_0804.save("E:\\A.常用文件夹\\驻点\\Python tool\\录入\\导出数据\\A08040000土地使用权类.xls")
                new_table_0800.save("E:\\A.常用文件夹\\驻点\\Python tool\\录入\\导出数据\\A08000000专利等无形类.xls")
                self.result_data_Text.insert(END,"保存数据完成！\n\n")
                tkinter.messagebox.showinfo(title='是否需要打印？',
                    message='如需打印请及时申请密钥！')
            except:
                self.result_data_Text.insert(END,"保存失败！若以打开文件请关闭！\n\n")
            self.result_data_Text.update()
        else:
            self.result_data_Text.insert(END,"————————————————————————————————————————————————————————————————\n")
            datastyle = xlwt.XFStyle()
            datastyle.num_format_str = 'yyyy-mm-dd'
            datastyle_year = xlwt.XFStyle()
            datastyle_year.num_format_str = 'yyyy'
            self.result_data_Text.insert(END,"开始读取Excel......\n")
            self.result_data_Text.insert(END,"————————————————————————————————————————————————————————————————\n")

            try:
                org_table = xlrd.open_workbook('E:\\A.常用文件夹\\驻点\\Python tool\\录入\\录入数据读取模板.xls').sheet_by_name('Sheet1') 
                zhejiu_table = xlrd.open_workbook('E:\\A.常用文件夹\\驻点\\yssj\\折旧方法设置新国.xls').sheet_by_name('折旧方法设置') 

                temp_table_0101 = xlrd.open_workbook('E:\\A.常用文件夹\\驻点\\yssj\\新资产导入表\\A01010000房屋类.xls', formatting_info = True)
                temp_table_0203 = xlrd.open_workbook('E:\\A.常用文件夹\\驻点\\yssj\\新资产导入表\\A02030000车辆类_设备.xls', formatting_info = True)
            except Exception as e:
                self.result_data_Text.insert(END,e)
                self.result_data_Text.insert(END,"请检查文件路径是否填写正确\n")
                self.result_data_Text.insert(END,"————————————————————————————————————————————————————————————————\n")
                sys.exit()

            new_table_0101 = xlutils.copy.copy(temp_table_0101)      
            new_table_0203 = xlutils.copy.copy(temp_table_0203)

            st_0101 = new_table_0101.get_sheet(0)          
            st_0203 = new_table_0203.get_sheet(0) 
            
            new_table_row_0101 = 2     
            new_table_row_0203 = 2

            nRows = org_table.nrows
            zhejiu_nRows = zhejiu_table.nrows
            self.result_data_Text.insert(END,"读取完成！\n")
            self.result_data_Text.insert(END,"————————————————————————————————————————————————————————————————\n")
            self.result_data_Text.insert(END,"开始遍历数据......\n")
            self.result_data_Text.insert(END,"————————————————————————————————————————————————————————————————\n")
            for i in range(1, nRows):  # 循环行数
                row_vals = org_table.row_values(i)
                type = str(row_vals[5])
                zhejiu_State = ""
                user_years = ""
                zichanlaiyuan = ""
                zhejiu_fun = ""
                match str(row_vals[20]):
                    case "1":
                        zichanlaiyuan = "新购"
                    case "2":
                        zichanlaiyuan = "调拨"
                    case "4":
                        zichanlaiyuan = "捐赠"
                    case "10":
                        zichanlaiyuan = "其他"
                jingfeilaiyuan = ""
                match str(row_vals[20]):
                    case "1":
                        jingfeilaiyuan = "财政拨款"
                    case "2":
                        jingfeilaiyuan = "调拨"
                    case "4":
                        jingfeilaiyuan = "捐赠"
                    case "10":
                        jingfeilaiyuan = "其他资金"
                for i in range(1, zhejiu_nRows): 
                    zhejiu_row_vals = zhejiu_table.row_values(i)
                    zhejiu_type = str(zhejiu_row_vals[0])
                    if(type == zhejiu_type):
                        zhejiu_State = str(zhejiu_row_vals[2])
                        user_years = str(zhejiu_row_vals[3])
                        if(str(zhejiu_row_vals[2]) == '不提折旧'):
                            zhejiu_fun = '不提折旧'
                        else:
                            if("{:.2f}".format(float(row_vals[3] - float(row_vals[4]))) == '0.00'):
                                zhejiu_fun = '已完成折旧'
                            else:
                                zhejiu_fun = '提折旧'
                if(type.startswith("A0101")):
                    st_0101.write(new_table_row_0101, 0, str(row_vals[0])) # 资产编号
                    st_0101.write(new_table_row_0101, 4, type) # 分类代码
                    st_0101.write(new_table_row_0101, 5, str(row_vals[2])) # 资产名称
                    st_0101.write(new_table_row_0101, 6, 1 if row_vals[24] == '' else "{:.2f}".format(float(row_vals[24]))) # 建筑面积
                    st_0101.write(new_table_row_0101, 7, str(row_vals[29])) # 计量单位
                    st_0101.write(new_table_row_0101, 10, str(row_vals[10])) # 管理部门
                    st_0101.write(new_table_row_0101, 11, str(row_vals[27])) # 管理人
                    st_0101.write(new_table_row_0101, 12, str(row_vals[10])) # 使用部门
                    st_0101.write(new_table_row_0101, 13, str(row_vals[27])) # 使用人
                    st_0101.write(new_table_row_0101, 14, "需确认") # 配置批准单位
                    st_0101.write(new_table_row_0101, 15, zichanlaiyuan) # 取得方式
                    st_0101.write(new_table_row_0101, 16, "需确认") # 建筑结构
                    st_0101.write(new_table_row_0101, 17, "需确认") # 采购组织形式
                    st_0101.write(new_table_row_0101, 20, xlrd.xldate_as_datetime(row_vals[9],0), datastyle) # 取得日期
                    st_0101.write(new_table_row_0101, 21, xlrd.xldate_as_datetime(row_vals[9],0), datastyle_year) # 建设年份
                    st_0101.write(new_table_row_0101, 22, str(row_vals[31])) # 坐落位置                
                    st_0101.write(new_table_row_0101, 23, "需确认") # 资产用途
                    st_0101.write(new_table_row_0101, 24, "需确认") # 层数
                    st_0101.write(new_table_row_0101, 25, "在用" if str(row_vals[11]) == '1' else "不在用") # 资产状态
                    st_0101.write(new_table_row_0101, 27, "否") # 是否共享共用
                    st_0101.write(new_table_row_0101, 28, "单位") # 使用责任主体
                    st_0101.write(new_table_row_0101, 29, "需确认") # 占地面积
                    st_0101.write(new_table_row_0101, 30, "需确认") # 地上建筑面积
                    st_0101.write(new_table_row_0101, 33, "需确认") # 房屋资产账中是否包含土地使用权
                    st_0101.write(new_table_row_0101, 34, "需确认") # 房屋资产账中包含的土地使用权面积
                    st_0101.write(new_table_row_0101, 35, "需确认") # 产权形式
                    st_0101.write(new_table_row_0101, 36, "需确认") # 权属证明
                    st_0101.write(new_table_row_0101, 37, str(row_vals[13])) # 权属证号
                    st_0101.write(new_table_row_0101, 38, xlrd.xldate_as_datetime(row_vals[14],0), datastyle) # 发证日期
                    st_0101.write(new_table_row_0101, 39, "国有") # 权属性质
                    st_0101.write(new_table_row_0101, 40, "需确认") # 权属统一登记情况
                    st_0101.write(new_table_row_0101, 41, "需确认") # 权属面积
                    st_0101.write(new_table_row_0101, 42, "需确认") # 证载用途
                    st_0101.write(new_table_row_0101, 43, "{:.2f}".format(float(row_vals[3]))) # 资产原值
                    st_0101.write(new_table_row_0101, 44, "{:.2f}".format(float(row_vals[4]))) # 累计折旧
                    st_0101.write(new_table_row_0101, 45, "{:.2f}".format(float(row_vals[3] - float(row_vals[4])))) # 账面净值
                    st_0101.write(new_table_row_0101, 46, "历史成本") # 价值类型
                    st_0101.write(new_table_row_0101, 52, zhejiu_State) # 折旧/摊销方法
                    st_0101.write(new_table_row_0101, 53, user_years) # 折旧/摊销年限
                    st_0101.write(new_table_row_0101, 56, zhejiu_fun) # 折旧/摊销状态
                    st_0101.write(new_table_row_0101, 58, "已入账") # 财务入账状态
                    st_0101.write(new_table_row_0101, 59, 1 if str(row_vals[12]) == '' else str(row_vals[12])) # 记账凭证号
                    st_0101.write(new_table_row_0101, 60, xlrd.xldate_as_datetime(row_vals[28],0), datastyle) # 记账日期
                    st_0101.write(new_table_row_0101, 61, jingfeilaiyuan) # 经费来源
                    st_0101.write(new_table_row_0101, 62, "1") # 项目代码
                    st_0101.write(new_table_row_0101, 65, "固定资产") # 单位会计科目
                    new_table_row_0101 = new_table_row_0101 + 1
                    # st_0101.write(new_table_row_0101, 0, str(row_vals[0])) # 资产编号
                    # st_0101.write(new_table_row_0101, 4, type) # 分类代码
                    # st_0101.write(new_table_row_0101, 5, str(row_vals[2])) # 资产名称
                    # st_0101.write(new_table_row_0101, 6, 1 if row_vals[24] == '' else "{:.2f}".format(float(row_vals[24]))) # 建筑面积
                    # st_0101.write(new_table_row_0101, 7, str(row_vals[29])) # 计量单位
                    # st_0101.write(new_table_row_0101, 10, str(row_vals[10])) # 管理部门
                    # st_0101.write(new_table_row_0101, 11, str(row_vals[27])) # 管理人
                    # st_0101.write(new_table_row_0101, 12, str(row_vals[10])) # 使用部门
                    # st_0101.write(new_table_row_0101, 13, str(row_vals[27])) # 使用人
                    # st_0101.write(new_table_row_0101, 14, "财政部门") # 配置批准单位
                    # st_0101.write(new_table_row_0101, 15, zichanlaiyuan) # 取得方式
                    # st_0101.write(new_table_row_0101, 16, "钢混结构") # 建筑结构
                    # st_0101.write(new_table_row_0101, 17, "单位集中采购") # 采购组织形式
                    # st_0101.write(new_table_row_0101, 20, xlrd.xldate_as_datetime(row_vals[9],0), datastyle) # 取得日期
                    # st_0101.write(new_table_row_0101, 21, xlrd.xldate_as_datetime(row_vals[9],0), datastyle_year) # 建设年份
                    # st_0101.write(new_table_row_0101, 22, str(row_vals[31])) # 坐落位置                
                    # st_0101.write(new_table_row_0101, 23, "办公") # 资产用途
                    # st_0101.write(new_table_row_0101, 24, "1") # 层数
                    # st_0101.write(new_table_row_0101, 25, "在用" if str(row_vals[11]) == '1' else "不在用") # 资产状态
                    # st_0101.write(new_table_row_0101, 27, "否") # 是否共享共用
                    # st_0101.write(new_table_row_0101, 28, "单位") # 使用责任主体
                    # st_0101.write(new_table_row_0101, 29, 1 if row_vals[24] == '' else "{:.2f}".format(float(row_vals[24]))) # 占地面积
                    # st_0101.write(new_table_row_0101, 30, 1 if row_vals[24] == '' else "{:.2f}".format(float(row_vals[24]))) # 地上建筑面积
                    # st_0101.write(new_table_row_0101, 33, "是") # 房屋资产账中是否包含土地使用权
                    # st_0101.write(new_table_row_0101, 34, 1 if row_vals[24] == '' else "{:.2f}".format(float(row_vals[24]))) # 房屋资产账中包含的土地使用权面积
                    # st_0101.write(new_table_row_0101, 35, "有产权证") # 产权形式
                    # st_0101.write(new_table_row_0101, 36, "暂无") # 权属证明
                    # st_0101.write(new_table_row_0101, 37, str(row_vals[13])) # 权属证号
                    # st_0101.write(new_table_row_0101, 38, xlrd.xldate_as_datetime(row_vals[14],0), datastyle) # 发证日期
                    # st_0101.write(new_table_row_0101, 39, "国有") # 权属性质
                    # st_0101.write(new_table_row_0101, 40, "已登记") # 权属统一登记情况
                    # st_0101.write(new_table_row_0101, 41, 1 if row_vals[24] == '' else "{:.2f}".format(float(row_vals[24]))) # 权属面积
                    # st_0101.write(new_table_row_0101, 42, "办公及业务用地") # 证载用途
                    # st_0101.write(new_table_row_0101, 43, "{:.2f}".format(float(row_vals[3]))) # 资产原值
                    # st_0101.write(new_table_row_0101, 44, "{:.2f}".format(float(row_vals[4]))) # 累计折旧
                    # st_0101.write(new_table_row_0101, 45, "{:.2f}".format(float(row_vals[3] - float(row_vals[4])))) # 账面净值
                    # st_0101.write(new_table_row_0101, 46, "历史成本") # 价值类型
                    # st_0101.write(new_table_row_0101, 52, zhejiu_State) # 折旧/摊销方法
                    # st_0101.write(new_table_row_0101, 53, user_years) # 折旧/摊销年限
                    # st_0101.write(new_table_row_0101, 56, zhejiu_fun) # 折旧/摊销状态
                    # st_0101.write(new_table_row_0101, 58, "已入账") # 财务入账状态
                    # st_0101.write(new_table_row_0101, 59, 1 if str(row_vals[12]) == '' else str(row_vals[12])) # 记账凭证号
                    # st_0101.write(new_table_row_0101, 60, xlrd.xldate_as_datetime(row_vals[28],0), datastyle) # 记账日期
                    # st_0101.write(new_table_row_0101, 61, jingfeilaiyuan) # 经费来源
                    # st_0101.write(new_table_row_0101, 62, "1") # 项目代码
                    # st_0101.write(new_table_row_0101, 65, "固定资产") # 单位会计科目
                elif(type.startswith("A0203")):
                    st_0203.write(new_table_row_0203, 0, str(row_vals[0])) # 资产编号
                    st_0203.write(new_table_row_0203, 4, type) # 分类代码
                    st_0203.write(new_table_row_0203, 5, str(row_vals[2])) # 资产名称
                    st_0203.write(new_table_row_0203, 6, str(row_vals[10])) # 使用部门
                    st_0203.write(new_table_row_0203, 7, "{:.2f}".format(float(row_vals[3]))) # 资产原值
                    st_0203.write(new_table_row_0203, 8, "{:.2f}".format(float(row_vals[4]))) # 累计折旧
                    st_0203.write(new_table_row_0203, 9, "{:.2f}".format(float(row_vals[3] - float(row_vals[4])))) # 账面净值
                    st_0203.write(new_table_row_0203, 10, zhejiu_State) # 折旧/摊销方法
                    st_0203.write(new_table_row_0203, 11, str(row_vals[29])) # 计量单位
                    st_0203.write(new_table_row_0203, 12, str(row_vals[27])) # 使用人  
                    st_0203.write(new_table_row_0203, 14, str(row_vals[10])) # 管理部门
                    st_0203.write(new_table_row_0203, 15, str(row_vals[27])) # 管理人  
                    st_0203.write(new_table_row_0203, 16, "单位") # 使用责任主体
                    st_0203.write(new_table_row_0203, 18, "在编") # 资产编制情况
                    st_0203.write(new_table_row_0203, 19, "需确认") # 车辆类型
                    st_0203.write(new_table_row_0203, 20, "本单位") # 采购实施单位
                    st_0203.write(new_table_row_0203, 21, xlrd.xldate_as_datetime(row_vals[9],0), datastyle) # 取得日期
                    st_0203.write(new_table_row_0203, 22, "财政部门") # 配置批准单位
                    st_0203.write(new_table_row_0203, 23, "单位集中采购") # 采购组织形式
                    st_0203.write(new_table_row_0203, 24, "是") # 是否统一标志
                    st_0203.write(new_table_row_0203, 25, xlrd.xldate_as_datetime(row_vals[9],0), datastyle) # 出厂日期
                    st_0203.write(new_table_row_0203, 26, zichanlaiyuan) # 取得方式
                    st_0203.write(new_table_row_0203, 28, xlrd.xldate_as_datetime(row_vals[9],0), datastyle) # 投入使用日期
                    st_0203.write(new_table_row_0203, 29, "否") # 是否共享共用
                    st_0203.write(new_table_row_0203, 30, "需确认") # 车辆行驶证
                    st_0203.write(new_table_row_0203, 31, "需确认") # 车辆识别代码
                    st_0203.write(new_table_row_0203, 32, "在用" if str(row_vals[11]) == '1' else "不在用") # 车辆状态
                    st_0203.write(new_table_row_0203, 34, "需确认") # 排放标准
                    st_0203.write(new_table_row_0203, 35, "国产" if str(row_vals[18]) == '' or str(row_vals[18]).startswith('无') else str(row_vals[18])) # 厂牌型号
                    st_0203.write(new_table_row_0203, 36, "常规" if str(row_vals[17]) == '' or str(row_vals[17]).startswith('无') else str(row_vals[17])) # 规格型号
                    st_0203.write(new_table_row_0203, 37, str(row_vals[19])) # 车辆用途
                    st_0203.write(new_table_row_0203, 38, "在用" if str(row_vals[11]) == '1' else "不在用") # 资产状态
                    st_0203.write(new_table_row_0203, 41, str(row_vals[22])) # 车牌号
                    st_0203.write(new_table_row_0203, 42, "需确认") # 动力类型
                    st_0203.write(new_table_row_0203, 44, xlrd.xldate_as_datetime(row_vals[9],0), datastyle) # 注册日期
                    st_0203.write(new_table_row_0203, 46, str(row_vals[21])) # 存放地点
                    st_0203.write(new_table_row_0203, 47, "需确认") # 汽车排气量
                    st_0203.write(new_table_row_0203, 51, "是") # 是否安装定位终端
                    st_0203.write(new_table_row_0203, 52, "固定资产") # 单位会计科目
                    st_0203.write(new_table_row_0203, 53, 1 if str(row_vals[12]) == '' else str(row_vals[12])) # 凭证号
                    st_0203.write(new_table_row_0203, 54, "1") # 项目代码
                    st_0203.write(new_table_row_0203, 55, "历史成本") # 价值类型
                    st_0203.write(new_table_row_0203, 58, zhejiu_fun) # 折旧/摊销状态
                    st_0203.write(new_table_row_0203, 59, user_years) # 折旧/摊销年限
                    st_0203.write(new_table_row_0203, 60, xlrd.xldate_as_datetime(row_vals[28],0), datastyle) # 记账日期
                    st_0203.write(new_table_row_0203, 61, "已入账") # 财务入账状态
                    new_table_row_0203 = new_table_row_0203 + 1
                else:
                    pass
            self.result_data_Text.insert(END,"遍历数据完成！\n")
            self.result_data_Text.insert(END,"————————————————————————————————————————————————————————————————\n")
            try:
                new_table_0101.save("E:\\A.常用文件夹\\驻点\\Python tool\\录入\\导出数据\\A01010000房屋类.xls")           
                new_table_0203.save("E:\\A.常用文件夹\\驻点\\Python tool\\录入\\导出数据\\A02030000车辆类_设备.xls")
                self.result_data_Text.insert(END,"保存数据完成！\n\n")
                tkinter.messagebox.showinfo(title='是否需要打印？',
                    message='如需打印请及时申请密钥！')
            except:
                self.result_data_Text.insert(END,"保存失败！若以打开文件请关闭！\n\n")
            self.result_data_Text.update()

    def get_type(self):
        self.result_data_Text.insert(END,"开始读取Excel......\n")
        try:
            wb = load_workbook("E:\\A.常用文件夹\\驻点\\Python tool\\打印\\打印编号读取模板.xlsx")
        except Exception as e:
            self.result_data_Text.insert(END,e)
            self.result_data_Text.insert(END,"请检查文件路径是否填写正确\n")
            self.result_data_Text.insert(END,"————————————————————————————————————————————————————————————————\n")
            sys.exit()
        w_sheet = wb['Sheet1']
        types = ""
        self.result_data_Text.insert(END,"开始遍历Excel......\n")
        for i in range(1, w_sheet.max_row + 1):
            type_no = (w_sheet.cell(row=i, column=1)).value
            types = types + type_no + ";"
        self.result_data_Text.insert(END,"读取完成，共读取{}个\n".format(w_sheet.max_row))
        with open("E:\\A.常用文件夹\\驻点\\Python tool\\打印\\打印编号导出数据.txt","w") as f:
            f.write(types)
        self.result_data_Text.insert(END,"文件保存完成！内容为{}\n\n".format(types))
        self.result_data_Text.update()

def gui_start():
    # 实例化出一个父窗口
    init_window = Tk()
    zmj_portal = MyGui(init_window)
    # 设置根窗口默认属性
    zmj_portal.set_init_window()
    # 父窗口进入事件循环,可以理解为保持窗口运行,否则界面不展示
    init_window.mainloop()

gui_start()


